<template>
  <a-modal
      width='618px'
      title='交付物检入'
      cancelText="取消"
      okText="确定"
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel">
      <commonUpload
      ref="check_upload"
        :oid='stringOid'
        :multiple='false'
        :paramsVisible='false'
        @handleUpload='handleUpload'
        @handleRemove='handleRemove'/>
  </a-modal>
</template>
<script>
import { mapGetters } from 'vuex'
import { checkinObj } from "@/api/fileSingle.js"
import copyACtion from '@/views/singleProject/fileSingle/el-common-js/copy'
let userinfo = JSON.parse(sessionStorage.getItem('userInfo'))
let oId = JSON.parse(sessionStorage.getItem('oid'))
// import commonUpload from '@/components/common/commonUpload'
import commonUpload from '@/views/singleProject/fileSingle/el-common/comm-el-onUpload'
export default {
  mixins: [copyACtion],
  data() {
    return {
      stringOid: '',
      visible: false,
      fileArr: [],
      types: {},
      trees: [],
    }
  },
  computed: {
    ...mapGetters({
      'fileSingleData': 'fileSingle'
    })
  },
  components: {
    commonUpload
  },
  props: {
    sessionData: {
      type: Array,
      default: () => []
    },//存入的session
  },
 
  mounted () {
    this.stringOid = oId + ''
  },
  methods: {
    /**
     * commonUpload 组件回调
     * 功能： props 选择交付物文件
     */
    handleUpload (info) {
      this.fileArr.push(info)
    },
    /**
     * commonUpload 组件回调
     * 功能：
     *      file 需要删除的文件
     *      fileList 删除之后的文件数组
     */
    handleRemove (file, fileList) {
      this.fileArr = []
    },
    /**
     * 确定按钮事件
     * 功能： 上传交付物
     */
    handleOk () {
      let _this = this
      let rules = {
        '请选择交付物文件....' : this.fileArr.length < 1
      }
     this.checkInUpFile({
        fileArr: this.fileArr,
        rules: rules,
        otherObj: { oid:this.sessionData[0].oid },
        callback: (res) => {
      //    console.log('上传文件的回调',res)
          if (res.code === 200) {
            let thisOid = _this.cycleID(res.data)
            checkinObj({userId: userinfo.loginName, oids: thisOid}).then((res1) => {
              this.visible = false
              if (res1 && res1.data.success) {
                _this.$message.success(res1.data.message)
                //  let newFileSingleTableItem = {}
                // newFileSingleTableItem.oid =  res.data.data[0].after
                // newFileSingleTableItem.state = _this.sessionData[0].state
                // fileSingle.tableArr[0].oid = res.data.data[0].after
                // sessionStorage.setItem('fileSingleTableItem', JSON.stringify(newFileSingleTableItem))
                // sessionStorage.setItem('fileSingle', JSON.stringify(fileSingle))
                // let sessionOid = JSON.parse(sessionStorage.getItem('fileSingleTableItem'))
               // console.log('检入之后的oid缓存',sessionOid);
                _this.$emit('initTableData')
              } else {
                _this.$message.error(res1.data.message)
              }
            })
          }
        }
      })
    //檀姐写的检入方法
      // this.checkInUpFile({
      //   fileArr: this.fileArr,
      //   rules: rules,
      //   otherObj: { oid: this.sessionData[0].oid },
      //   callback: (res) => {
      // //    console.log('上传文件的回调',res)
      //     if (res.code === 200) {
      //       let thisOid = _this.cycleID(res.data)
      //       checkinObj({userId: userinfo.loginName, oids: thisOid}).then((res) => {
      //         this.visible = false
      //         if (res && res.data.success) {
      //           // let newFileSingleTableItem = {}
      //           // newFileSingleTableItem.oid =  res.data.data[0].after
      //           // newFileSingleTableItem.state = item.state
      //           // sessionStorage.setItem('fileSingleTableItem', JSON.stringify(newFileSingleTableItem))
      //           // console.log('检入操作后的接口回调返回数据',res.data)
      //           // console.log('检入后的sessionStorage',)
      //           _this.$message.success(res.data.message)
      //           _this.$emit('initTableData')
      //         } else {
      //           _this.$message.error(res.data.message)
      //         }
      //       })
      //     }
      //   }
      // })
      this.$refs.check_upload.fileList = []
    },
    /**
     * 取消按钮事件
     */
    handleCancel () {
      this.visible = false
      this.$refs.check_upload.fileList = []
    },
    /**
     * 开启弹窗
     * key 上级需要开启那个弹窗的key props上级tree选中的tree，propsArr 上级table选中的数据
     */
    openModal (start,sessionData, props, propsArr) {
      this.visible = start
    }
  }
}
</script>
<style lang="less" scoped>
.width_410 {
  width: 410px;
}
</style>